/**
 * <b>Attribute class:</b>
 * <hr color=grey size=1>
 * 
 * Attribute is this kinds of string, first part is name, second part is
 * char '=', the third part is value.
 * <br>
 * This class can parse this kinds of string. Three cases is under the 
 * considering:
 * <ol>
 * 		<li>A=B
 * 		<li>A="B"
 * 		<li>A='B'
 * </ol>
 *  
 * @author zozoh  created @ 2006
 *
 */
ihelpuoo.util.Attribute = function(content)
{
	this.name = null;
	this.value = null;
	this.seperator = "=";
	
	if(content)
		this.valueOf(content);
}

ihelpuoo.util.Attribute.prototype
=
{
	/**
	 * Parse Attribute expression from a string. If you give the second
	 * paramerter, it will override the seperator attribute of current
	 * instance. 
	 * 
	 * @param v: attribute expression string
	 * @param <i>seperator</i>: the seperator of name & value.
	 */
	valueOf: function(v,seperator)
	{
		if (v != null)
		{
			var str = v;
			this.seperator = seperator;
			var index = str.indexOf(this.seperator);
			if (index >= 0)
			{
				this.name = ihelpuoo.trim(str.substring(0,index));
				this.value = ihelpuoo.trim(str.substring(index + 1));
				if ((ihelpuoo.startsWith(this.value,"\"") && ihelpuoo.endsWith(this.value,"\""))
					||
					ihelpuoo.startsWith(this.value,"'") && ihelpuoo.endsWith(this.value,"'")
				   )
				{
					this.value = this.value.substring(1,this.value.length - 1);
				}
			}
			else
			{
				this.name = str;
				this.value = null;
			}
		}
	}
	
	
	,
	/**
	 * @return the expression string
	 */
	toString: function()
	{
		return name + this.seperator + value; 
	}
	
	,
	/**
	 * Alias of toString() function.
	 * @return String.
	 */
	dump: function()
	{
		return this.toString();
	}
}